from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import Login



def getMyLineLoans(driver):
    driver.find_element(By.XPATH, '//nav[@class="sidebar-main"]/ul/li[4]/a').click()
    # 点击个人中心
    time.sleep(1)
    driver.find_element(By.XPATH, '//nav[@class="sidebar-main"]/ul/li[4]/ul/li[2]').click()
    # 点击我的借贷
    time.sleep(1)

    return driver.find_element(By.XPATH,'/html/body/div[1]/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
    # 借贷信息条数


def onlineLoans2(driver):
    time.sleep(1)
    driver.find_element(By.XPATH,'//nav[@class="sidebar-main"]/ul/li[3]/a').click()
    # 点击金融工具
    time.sleep(1)
    driver.find_element(By.XPATH,'//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
    # 点击安全网贷
    time.sleep(1)


def onlineLoans(name,password,money,moneyTime):

    driver = Login.login1(name,password)
    text1 = getMyLineLoans(driver)
    onlineLoans2(driver)
    driver.find_element(By.XPATH,"//input[@id='amount']").send_keys(money)
    driver.find_element(By.XPATH,"//input[@id='term']").send_keys(moneyTime)
    driver.find_element(By.XPATH,"//button[@id='submit']").click()
    # 点击申请按钮
    time.sleep(1)
    driver.find_element(By.XPATH,"//div[@class='jconfirm-buttons']/button[1]").click()
    # 点击确认按钮
    time.sleep(3)
    text2 = getMyLineLoans(driver)

    return [driver,text1,text2]



def onlineLoans_21(name,password,money,moneyTime):
    driver = Login.login1(name, password)

    onlineLoans2(driver)
    driver.find_element(By.XPATH, "//input[@id='amount']").send_keys(money)
    driver.find_element(By.XPATH, "//input[@id='term']").send_keys(moneyTime)
    driver.find_element(By.XPATH, "//button[@id='submit']").click()
    # 点击申请按钮
    time.sleep(1)
    driver.find_element(By.XPATH, "//div[@class='jconfirm-buttons']/button[1]").click()
    # 点击确认按钮
    time.sleep(3)

    return driver




def onlineLoans_2(name,password):
    driver = Login.login1(name, password)

    driver.find_element(By.XPATH,"//nav[@class='sidebar-main']/ul/li[5]/a").click()
    # 点击网贷管理
    time.sleep(1)
    driver.find_element(By.XPATH,"//nav[@class='sidebar-main']/ul/li[5]/ul/li[1]/a").click()
    # 选择网贷审核
    time.sleep(1)

    driver.find_element(By.XPATH,"//nav[contains(@aria-label,'Page')]/ul/li[last()]/a").click()
    # 点击末页按钮
    time.sleep(2)

    driver.find_element(By.XPATH,"//div[@class='card-body']/div/table/tbody/tr[last()]/td[last()]/button[1]").click()
    # 点击 审核通过 按钮
    time.sleep(2)
    driver.find_element(By.XPATH,"//div[@class='jconfirm-buttons']/button[1]").click()
    # 点击确认按钮
    time.sleep(2)

    driver.quit()



